home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / lotus / lotus032.dsk / GTSCRPT.LSS < prev    next >
Text File  |  1995-10-04  |  40KB  |  935 lines

  1. OPTION DECLARE                          '// force explicit delcaration of variables
  2. Use "gtscrpt2"
  3.  
  4.  
  5. '//-------------------------------------------------------------------------------------
  6. '// Goals script
  7. '//-------------------------------------------------------------------------------------
  8.  
  9. '// sets new coordinates for GoalInfo (for dgm's that have 
  10. '// text shapes positioned vertically) - does not store text
  11. '//--------------------------------------------------------------------------------
  12. Public SUB FindTopDownTextShapes(GoalInfo() As GoalsStruct, ScriptID As Integer)
  13.    Dim    Index            As Integer,        _
  14.            Count            As Integer,        _
  15.            i                As Integer,        _
  16.             ArraySize    As Integer
  17.  
  18.  
  19.     If(ScriptID = ObjectivesScript) Then
  20.         ArraySize = MaxObjectives
  21.     ElseIf(ScriptID = PyramidScript) Then
  22.         ArraySize = MaxPyramidEvents
  23.     End If
  24.  
  25.     For i = 1 To (ArraySize)                                            '// zero out all position information 
  26.         GoalInfo(i).Position = 0                                        '// in case it has info about old diagrams
  27.     Next i
  28.  
  29.    Count = 0
  30.    ForAll Object in Selection.SelectedObjects
  31.         If(Object.IsText) Then                                            '// sorts by left coordinate of each text shape found
  32.             Index = Count 
  33.             If(Count <> 0) Then
  34.                 While((GoalInfo(Index).Position < Object.Top) AND (Index > 0))
  35.                     GoalInfo(Index+1).Position = GoalInfo(Index).Position
  36.                     Index = Index - 1
  37.                 Wend
  38.             End If
  39.             GoalInfo(Index+1).Position = Object.Top
  40.             Count = Count + 1
  41.         End If
  42.    End ForAll
  43. END SUB
  44.  
  45.  
  46. '// Finds specified goal among currently selected DrawObject's
  47. Public FUNCTION SelectLevel(index As Integer, GoalInfo() As GoalsStruct) AS DrawObject
  48.    ForAll Object in Selection.SelectedObjects
  49.       If(Object.isText AND Object.top = GoalInfo(index).position) Then
  50.          set SelectLevel = Object
  51.          Exit ForAll
  52.       End If
  53.    End ForAll
  54. END FUNCTION
  55.  
  56. '// Finds specified goal among currently selected DrawObject's
  57. PRIVATE FUNCTION SelectGoal(index As Integer, GoalInfo() As GoalsStruct) AS DrawObject
  58.    ForAll Object in Selection.SelectedObjects
  59.       If(Object.isText AND Object.top = GoalInfo(index).position) Then
  60.          set SelectGoal = Object
  61.          Exit ForAll
  62.       End If
  63.    End ForAll
  64. END FUNCTION
  65.  
  66. '// Initializes array of objectives, fills array with text, also used by Send Email script
  67. '//     InPuts: 
  68. '//    OutPuts:    GoalInfo()    - array of GoalsSruct's filled in with position and text of each objective
  69. '//                Count            - Number of Objectives found
  70. '//                NumGoals        - Number of calculated Objectives (based upon grouping assumptions of diagrams in branch.dgm)
  71. '//    Returns:    DrawObject
  72. '//------------------------------------------------------------------------------------------------------------------------
  73. PUBLIC FUNCTION InitGoalsInfo(GoalInfo() As GoalsStruct, Count As Integer, _
  74.                                             DefaultButton As Integer, NumGoals As Integer) As _
  75.                                             DrawObject
  76.     Dim    i            As Integer,        _
  77.             Index        As Integer,        _
  78.             x            As Integer,        _
  79.             Temp        As DrawObject, _
  80.             Goals        As DrawObject
  81.  
  82.  
  83.     For x = 1 to MaxObjectives                                     '// Init array of GoalsStruct's
  84.       GoalInfo(x).position = 0
  85.       GoalInfo(x).Text = ""
  86.    Next x
  87.     Set Temp = CurrentPage.FindObject(GoalsDgmName)          '// find goals diagram
  88.    Set Goals = Temp.Replicate()                                '// take dgm out of pb to ungroup
  89.    Temp.Cut                                                    '// delete dgm in pb
  90.     Selection.ClearSelection
  91.    Goals.Ungroup                                               '// ungroup dgm copied - not in pb
  92.  
  93.    If(Selection.SelectionCount < 3 OR Selection.SelectionCount > 12) Then
  94.       MessageBox InvalidDiagram, 0, ErrorMsg                        '// Check for invalid diagram
  95.       EndScript
  96.    End If
  97.  
  98.    SELECT CASE(Selection.SelectionCount)                      '// Find number of goals
  99.       Case 3: NumGoals = 2
  100.       Case 4: NumGoals = 3
  101.       Case 5: NumGoals = 4
  102.       Case 6: NumGoals = 5
  103.       Case 7: NumGoals = 6
  104.       Case 8: NumGoals = 7
  105.    END SELECT
  106.  
  107.    If(NumGoals = MaxObjectives) Then                                  '// if 7 goals default radio button for delete to be selected
  108.       DefaultButton = 1
  109.    Else                                                                '// otherwise default to add
  110.       DefaultButton = 0
  111.    End If
  112.  
  113.    Count = 0
  114.    ForAll Obj in Selection.SelectedObjects                       '// finds text shapes and stores text
  115.         If(Obj.IsText) Then                                                '// sorts by top coordinate of each text shape found
  116.             Index = Count
  117.             If(Count <> 0) Then
  118.                 While((GoalInfo(Index).Position < Obj.Top) AND (Index > 0))
  119.                     GoalInfo(Index+1) = GoalInfo(Index)
  120.                     Index = Index - 1
  121.                 Wend
  122.             End If
  123.             GoalInfo(Index+1).Position = Obj.Top
  124.             GoalInfo(Index+1).Text = Obj.Text
  125.             Count = Count + 1
  126.     For  x = 1 to Count
  127.     print GoalInfo(x).text, GoalInfo(x).position
  128.     next x
  129.     print "------------"
  130.         End If
  131.    End ForAll
  132.     
  133. print "count=",count
  134.    Set InitGoalsInfo = Selection.Group()
  135. END FUNCTION
  136.  
  137.  
  138. Public SUB Objectives(bSAlliance As Integer)
  139.    Dim    PackedVal        As Long,            _
  140.            DgmPath            As String,        _
  141.            x                    As Integer,        _
  142.            i                    As Integer,        _
  143.            j                    As Integer,        _
  144.            Count                As Integer,        _
  145.            NumToAdd            As Integer,        _
  146.            NumToDel            As Integer,        _
  147.            NumGoals            As Integer,        _
  148.            DefaultButton    As Integer,        _
  149.             MaxSpinnerVal    As Integer,        _
  150.            Temp                As DrawObject,    _
  151.            Goals                As DrawObject,    _
  152.            GoalInfo(MaxObjectives) As GoalsStruct
  153.  
  154.  
  155.       Set Goals = InitGoalsInfo(GoalInfo(), Count, DefaultButton, NumGoals)
  156.  
  157.    If(Count > NumGoals) Then                                            '//  if diagram has incorrect layout, too much text
  158.       MESSAGEBOX InvalidDiagram, 0, ErrorMsg
  159.    Else
  160.       DgmPath = [Freelance].Preferences.TemplateDir + BranchDgmFileName
  161.  
  162.         If(NumGoals = MaxObjectives) Then
  163.             MaxSpinnerVal = MaxObjectives
  164.         Else
  165.             MaxSpinnerVal = NumGoals + 1
  166.         End If
  167.  
  168.       '// Strategic Alliance needs different wording, so depending on flag launch dlg appropriately
  169.         If(bSAlliance = 0) Then
  170.             PackedVal = CurrentDocument.RunDialog(1, ObjDlgTitle, DiagramNote, ObjAddQuestion, _
  171.                                                 ObjDelQuestion, DefaultButton, NULLSTR, _
  172.                                                 NULLSTR, "1", STR$(MaxSpinnerVal), 1, _
  173.                                                 NumGoals)
  174.         Else
  175.           PackedVal = CurrentDocument.RunDialog(1, GoalDlgTitle, DiagramNote, GoalAddQuestion, _
  176.                                                      GoalDelQuestion, DefaultButton, NULLSTR, _
  177.                                                     NULLSTR, "1", STR$(MaxSpinnerVal), 1, _
  178.                                                     NumGoals)
  179.         End If
  180.  
  181.  
  182.       If((PackedVal AND BitField9) = BitField9) Then                    '// User ok'd dlg
  183.          If((PackedVal AND BitField8) <> BitField8) Then          '// ADD Goal
  184.                NumToAdd = PackedVal AND BitFields0To7
  185.                If((NumToAdd > 0) AND (NumToAdd <= 7)) Then
  186.                   If(NumGoals = MaxObjectives) Then                   '// too many objectives, can't add
  187.                      MESSAGEBOX AddError, 0, ErrorMsg
  188.                      Goals.PutIntoPlacementBlock(DgmPBID)        
  189.                      Goals.name = GoalsDgmName                        '// so we can find it later
  190.                Else                             
  191.                      Goals.Cut                                           '// delete old diagram
  192.                      set Goals = CurrentPage.CreateSymbol(DgmPath, NumGoals)
  193.                      Selection.ClearSelection
  194.                      Goals.Ungroup
  195.                 
  196.                      FindTopDownTextShapes GoalInfo(), ObjectivesScript    '// Find coordinates for each objective and sort
  197.                         
  198.                   x = NumGoals + 1                                            '// add new objective in array
  199.                      WHILE(x > NumToAdd)
  200.                         GoalInfo(x).Text = GoalInfo(x-1).Text
  201.                         x = x - 1
  202.                      WEND
  203.                       GoalInfo(NumToAdd).Text = ""                     '// not necessary since not used, but
  204.                                                                         '// just to be safe
  205.                   For x = 1 TO (NumToAdd -1)                           '// re-insert old objectives
  206.                         set Temp = SelectGoal(x, GoalInfo())
  207.                             If(StrCompare(GoalInfo(x).Text, NULLSTR)) Then    '// Don't replace with Null String, 
  208.                             Temp.Text = GoalInfo(x).Text                        '// removes prompt text
  209.                             End If
  210.                      Next x
  211.                        For x = (NumToAdd+1) TO (NumGoals+1)
  212.                         set Temp = SelectGoal(x, GoalInfo())
  213.                             If(StrCompare(GoalInfo(x).Text, NULLSTR)) Then    '// Don't replace with Null String, 
  214.                             Temp.Text = GoalInfo(x).Text                        '// removes prompt text
  215.                             End If
  216.                   Next x
  217.                       set Goals = Selection.Group()                     '// put pieces back together
  218.                      Goals.PutIntoPlacementBlock(DgmPBID)        
  219.                      Goals.name = GoalsDgmName                        '// so we can find it later
  220.                   End If
  221.                End If
  222.             Else                                                         '// delete an objective
  223.                NumToDel = PackedVal AND BitFields0To7
  224.             If(NumGoals = MinObjectives) Then
  225.                   MESSAGEBOX DeleteError, 0, ErrorMsg
  226.                   Goals.PutIntoPlacementBlock(DgmPBID)                   '// restore objective in pb
  227.                     Goals.name = GoalsDgmName                            '// so we can find it later
  228.                ElseIf((NumToDel <= NumGoals) AND (NumToDel > 0)) Then
  229.                   Goals.Cut
  230.                set Goals = CurrentPage.CreateSymbol(DgmPath, NumGoals-2)
  231.                     Selection.ClearSelection
  232.                   Goals.Ungroup
  233.             
  234.                   FindTopDownTextShapes GoalInfo(), ObjectivesScript    '// Find coordinates for each objective and sort
  235.                
  236.                For x = NumToDel TO (NumGoals - 1)                        '// delete objective in array of GoalStruct's
  237.                      GoalInfo(x).Text = GoalInfo(x+1).Text
  238.                   Next x
  239.                    GoalInfo(NumGoals).Text = ""                       '// clear last item in array
  240.                 
  241.                For x = 1 TO (NumGoals - 1)                            '// re-insert old objectives
  242.                         set Temp = SelectGoal(x, GoalInfo())
  243.                         If(StrCompare(GoalInfo(x).Text, NULLSTR)) Then    '// Don't replace with Null String, 
  244.                          Temp.Text = GoalInfo(x).text                        '// removes prompt text
  245.                         End If
  246.                   Next x
  247.                 
  248.                 Set Goals = Selection.Group()                         '// put pieces back together
  249.                   Goals.PutIntoPlacementBlock(DgmPBID)
  250.                Goals.name = GoalsDgmName                             '// so we can find later
  251.              End If
  252.             End If
  253.         Else                                                                            '// user canceled out of dlg
  254.              Goals.PutIntoPlacementBlock(101)                           '// so we can find it later
  255.             Goals.name = GoalsDgmName                                  '// restore goal in pb                   
  256.        End If                       
  257.          Selection.ClearSelection
  258.     End If
  259. END SUB
  260.  
  261.  
  262. Public Sub Goals()
  263.     Objectives(0)
  264. End Sub
  265.  
  266. '// wrapper so we know if we've been called from Strategic Alliance, in which case 'objectives' need to be 'goals'
  267. '// Don't want ot changed API because then we would have to re-attach all scripts
  268. Public Sub SA_Goals()
  269.     Objectives(1)
  270. End Sub
  271.  
  272.  
  273. '//--------------------------------------------------------------------------------------
  274. '// Pyramid script
  275. '//--------------------------------------------------------------------------------------
  276.  
  277. PUBLIC SUB Pyramid()
  278.    Dim    PackedVal        As Long,            _
  279.            DgmPath            As String,        _
  280.               NumLevels        As Integer,        _
  281.             MaxSpinnerVal    As Integer,        _
  282.            Count                As Integer,        _
  283.            DefaultButton    As Integer,        _
  284.            x                    As Integer,        _
  285.            NumToAdd            As Integer,     _
  286.             NumToDel            As Integer,        _
  287.             i                    As Integer,        _
  288.             Index                As Integer,        _
  289.            Pyrmd                As DrawObject,    _
  290.            Temp                As DrawObject,    _
  291.            GoalInfo(MaxPyramidEvents)    As GoalsStruct
  292.  
  293.  
  294.    For x = 1 to MaxPyramidEvents                             '// Init array of GoalsStruct's
  295.       GoalInfo(x).position = 0
  296.       GoalInfo(x).Text = ""
  297.    Next x
  298.  
  299.    Set Temp = CurrentPage.FindObject(PyramidDgmName)        '// find goals diagram
  300.    Set Pyrmd = Temp.Replicate()                            '// take dgm out of pb to ungroup
  301.    Temp.Cut                                                '// delete dgm in pb
  302.     Selection.ClearSelection
  303.    Pyrmd.Ungroup                                           '// ungroup dgm copied - not in pb
  304.  
  305.    If(Selection.SelectionCount < 4 OR Selection.SelectionCount > 10) Then
  306.       MessageBox InvalidDiagram, 0, ErrorMsg
  307.       EndScript
  308.    End If                                                         '// Checking for invalid diagram
  309.  
  310.    SELECT CASE(Selection.SelectionCount)                      '// Find number of Pyrmd
  311.        Case 4: NumLevels = 2
  312.        Case 6: NumLevels = 3
  313.        Case 8: NumLevels = 4
  314.        Case 10: NumLevels = 5
  315.    END SELECT
  316.  
  317.    If(NumLevels = MaxPyramidEvents) Then                      '// if max sections default radio button for delete
  318.       DefaultButton = 1
  319.    Else                                                                '// otherwise default to add
  320.       DefaultButton = 0
  321.    End If
  322.  
  323.    Count = 0
  324.    ForAll Obj In Selection.SelectedObjects                   '// finds text shapes and stores text
  325.         If(Obj.IsText) Then                                            '// sorts by top coordinate of each text shape found
  326.             Index = Count
  327.             If(Count <> 0) Then
  328.                 While((GoalInfo(Index).Position < Obj.Top) AND (Index > 0))
  329.                     GoalInfo(Index+1) = GoalInfo(Index)
  330.                     Index = Index - 1
  331.                 Wend
  332.             End If
  333.             GoalInfo(Index+1).Position = Obj.Top
  334.             GoalInfo(Index+1).Text = Obj.Text
  335.             Count = Count + 1
  336.     For  x = 1 to Count
  337.     print GoalInfo(x).text, GoalInfo(x).position
  338.     next x
  339.     print "------------"
  340.         End If
  341.    End ForAll
  342.     
  343. print "count=",count
  344.  
  345.    set Pyrmd = Selection.Group()
  346.  
  347.    If(Count > NumLevels) Then                                '//  if diagram has incorrect layout, too much text
  348.       MESSAGEBOX InvalidDiagram, 0, ErrorMsg
  349.    Else
  350.       DgmPath = [Freelance].Preferences.TemplateDir + PyramidDgmFileName
  351.  
  352.         If(NumLevels = MaxPyramidEvents) Then
  353.             MaxSpinnerVal = MaxPyramidEvents
  354.         Else
  355.             MaxSpinnerVal = NumLevels + 1
  356.         End If
  357.  
  358.       PackedVal = CurrentDocument.RunDialog(1, SectionDlgTitle, DiagramNote, SectionAddQuestion, SectionDelQuestion, _
  359.                                                 DefaultButton, NULLSTR, NULLSTR, "1", STR$(MaxSpinnerVal), 1, NumLevels)
  360.  
  361.       If((PackedVal AND 512) = 512) Then                                             '// User ok'd dlg
  362.          If((PackedVal AND 256) <> 256) Then                                         '// ADD Goal
  363.             NumToAdd = PackedVal AND 255
  364.             If((NumToAdd > 0) AND (NumToAdd <= 7)) Then
  365.                If(NumLevels = MaxPyramidEvents) Then                                '// too many Pyrmd, can't add
  366.                   MESSAGEBOX AddError, 0, ErrorMsg
  367.                    Pyrmd.PutIntoPlacementBlock(DgmPBID)                                 '// restore section in pb
  368.                         Pyrmd.Name = PyramidDgmName                                       '// so we can find it later
  369.                 Else                                                                     '// add goal
  370.                   Pyrmd.Cut                                                           '// remove old dgm
  371.                   Set Pyrmd = CurrentPage.CreateSymbol(DgmPath, NumLevels)
  372.                         Selection.ClearSelection
  373.                   Pyrmd.Ungroup
  374.  
  375.                   FindTopDownTextShapes GoalInfo(), PyramidScript                    '// Find coordinates for each section 
  376.                                                                                                         '// and sort
  377.                   x = NumLevels + 1                                                 '// add new section in array
  378.                   WHILE(x > NumToAdd)
  379.                      GoalInfo(x).Text = GoalInfo(x-1).Text
  380.                      x = x - 1
  381.                   WEND
  382.  
  383.                   GoalInfo(NumToAdd).Text = ""                                         '// not necessary since not used, but
  384.                                                                                      '// just to be safe
  385.                   For x = 1 TO (NumToAdd -1)                                         '// re-insert old sections
  386.                      Set Temp = SelectLevel(x, GoalInfo())
  387.                             If(StrCompare(GoalInfo(x).Text, NULLSTR)) Then                '// Don't replace with Null String, 
  388.                          Temp.Text = GoalInfo(x).Text                                    '// removes prompt text
  389.                             End If
  390.                   Next x
  391.                   For x = (NumToAdd+1) TO (NumLevels+1)
  392.                      Set Temp = SelectLevel(x, GoalInfo())
  393.                             If(StrCompare(GoalInfo(x).Text, NULLSTR)) Then                '// Don't replace with Null String, 
  394.                          Temp.Text = GoalInfo(x).Text                                    '// removes prompt text
  395.                             End If
  396.                   Next x
  397.  
  398.                   set Pyrmd = Selection.Group()                                       '// put pieces back together
  399.                   Pyrmd.PutIntoPlacementBlock(DgmPBID)                              '// assume pb has id of 101
  400.                   Pyrmd.Name = PyramidDgmName                                        '// so we can find it later
  401.                End If
  402.             End If
  403.          Else                                                                          '// delete goal
  404.             NumToDel = PackedVal AND 255
  405.             If(NumLevels = MinPyramidEvents) Then
  406.                MESSAGEBOX DeleteError, 0, ErrorMsg
  407.                Pyrmd.PutIntoPlacementBlock(DgmPBID)                                 '// restore goal in pb
  408.                     Pyrmd.Name = PyramidDgmName                                            '// so we can find it later
  409.             ElseIf ((NumToDel <= NumLevels) AND (NumToDel > 0)) Then
  410.                Pyrmd.Cut
  411.                Set Pyrmd = CurrentPage.CreateSymbol(DgmPath, NumLevels-2)
  412.                     Selection.ClearSelection
  413.                Pyrmd.Ungroup
  414.  
  415.                FindTopDownTextShapes GoalInfo(), PyramidScript                  '// Find coordinates for each section
  416.                                                                                                         '//  and sort
  417.                For x = NumToDel TO (NumLevels - 1)                                   '// delete goal in array of Pyrmdtruct's
  418.                   GoalInfo(x).Text = GoalInfo(x+1).Text
  419.                Next x
  420.  
  421.                GoalInfo(NumLevels).Text = ""                                         '// clear last item in array
  422.  
  423.                For x = 1 TO (NumLevels - 1)                                          '// re-insert old Pyrmd
  424.                   Set Temp = SelectLevel(x, GoalInfo())
  425.                         If(StrCompare(GoalInfo(x).Text, NULLSTR)) Then                    '// Don't replace with Null String, 
  426.                       Temp.Text = GoalInfo(x).Text                                        '// removes prompt text
  427.                         End If
  428.                Next x
  429.  
  430.                Set Pyrmd = Selection.Group()                                           '// put pieces back together
  431.                Pyrmd.PutIntoPlacementBlock(DgmPBID)
  432.                Pyrmd.Name = PyramidDgmName                                           '// so we can find later
  433.             End If
  434.          End If
  435.       Else
  436.          Pyrmd.PutIntoPlacementBlock(DgmPBID)                                        '// user canceled out of dlg
  437.             Pyrmd.Name = PyramidDgmName                                                    '// restore dgm in pb
  438.       End If                                             
  439.       Selection.ClearSelection
  440.    End If
  441. END SUB
  442.  
  443.  
  444. '//--------------------------------------------------------------------------------------
  445. '// Used by section scripts to find a particular section
  446. '//--------------------------------------------------------------------------------------
  447. Public FUNCTION SelectSegment(index As Integer, GoalInfo() As SegmentStruct) AS DrawObject
  448.    ForAll Object in Selection.SelectedObjects
  449.       If(Object.isText AND Object.Left = GoalInfo(index).LeftPos _
  450.               AND Object.Top = Goalinfo(index).TopPos) Then
  451.          set SelectSegment = Object
  452.          Exit ForAll
  453.       End If
  454.    End ForAll
  455. END FUNCTION
  456.  
  457.  
  458. '//--------------------------------------------------------------------------------------
  459. '// used by two column section scripts to sort array of sections 
  460. '//--------------------------------------------------------------------------------------
  461. '// sets new coordinates for Level - does not store text
  462. Public SUB FindSegmenttextShapes(GoalInfo() As SegmentStruct)
  463.    Dim    Index    As Integer,    _
  464.            Count As Integer,    _
  465.            i        As Integer, _
  466.             x as integer
  467.  
  468.     For x = 1 To MaxSegments
  469.         GoalInfo(x).TopPos = 0
  470.         GoalInfo(x).LeftPos = 0
  471.     Next x
  472.  
  473.    Count = 0
  474.    ForAll Object in Selection.SelectedObjects
  475.       If(Object.IsText) Then
  476.             Index = Count
  477.          If(Count <> 0) Then
  478.                While((Index > 0) AND (GoalInfo(Index).TopPos < Object.Top))
  479. print "Index=",Index
  480.                         GoalInfo(Index+1).TopPos = GoalInfo(Index).TopPos
  481.                         GoalInfo(Index+1).LeftPos = GoalInfo(Index).LeftPos
  482.                         Index = Index - 1
  483.                 Wend
  484.  
  485.                 If(GoalInfo(Index).LeftPos > Object.Left) Then                        '// set to correct column
  486.                     GoalInfo(Index+1).TopPos = GoalInfo(Index).TopPos
  487.                     GoalInfo(Index+1).LeftPos = GoalInfo(Index).LeftPos
  488.                     Index = Index - 1
  489.                 End If
  490.             End If
  491.             GoalInfo(Index+1).TopPos = Object.Top
  492.             GoalInfo(Index+1).LeftPos = Object.Left
  493.          Count = Count + 1
  494.  
  495.     For  x = 1 to Count
  496.     print GoalInfo(x).Text, GoalInfo(x).leftpos, GoalInfo(x).TopPos
  497.     next x
  498.     print "------------"
  499.  
  500.       End If
  501.    End ForAll
  502. END SUB
  503.  
  504.  
  505. '//--------------------------------------------------------------------------------------
  506. '// Two column Segment script
  507. '//--------------------------------------------------------------------------------------
  508. PUBLIC SUB Segment()
  509.    Dim     PackedVal        As Long,        _
  510.            DgmPath            As String,    _
  511.            MaxSpinnerVal    As Integer,    _
  512.            MaxObjectCount    As Integer,    _
  513.            MinObjectCount As Integer, _
  514.            NumSections        As Integer, _
  515.            Count                As Integer,    _
  516.            DefaultButton    As Integer, _
  517.            x                    As Integer, _
  518.            NumToAdd            As Integer, _
  519.             NumToDel            As Integer, _
  520.             i                    As Integer, _
  521.             Index                As Integer,    _
  522.             MaxDeleteVal    As Integer, _
  523.            Section            As DrawObject,    _
  524.            Temp                As DrawObject,    _
  525.            SectionInfo(MaxSegments)    As SegmentStruct
  526.    
  527.  
  528.    MaxObjectCount = MaxSegments + 1
  529.    MinObjectCount    = MinSegments + 1
  530.  
  531.    For x = 1 to MaxSegments                                 '// Init array of SegmentStruct's
  532.         SectionInfo(x).LeftPos        = 0
  533.         SectionInfo(x).TopPos         = 0
  534.       SectionInfo(x).Text     = ""
  535.    Next x
  536.  
  537.    Set Temp = CurrentPage.FindObject(SegmentDgmName)  '// find Section diagram
  538.    Set Section = Temp.Replicate()                        '// take dgm out of pb to ungroup
  539.    Temp.Cut                                            '// delete dgm in pb
  540.     Selection.ClearSelection
  541.    Section.Ungroup                                       '// ungroup dgm copied - not in pb
  542.  
  543.    If(Selection.SelectionCount < MinObjectCount OR Selection.SelectionCount > MaxObjectCount) Then
  544.       MessageBox InvalidDiagram, 0, ErrorMsg
  545.       EndScript
  546.    End If                                                     '// Checking for invalid diagram
  547.  
  548.    SELECT CASE(Selection.SelectionCount)                  '// Find number of segments
  549.        Case 5: NumSections = 4
  550.        Case 7: NumSections = 6
  551.        Case 9: NumSections = 8
  552.        Case 11: NumSections = 10
  553.        Case 13: NumSections = 12
  554.    END SELECT
  555.  
  556.    If(NumSections = MaxSegments) Then                      '// if max number of segments, default to delete
  557.       DefaultButton = 1
  558.    Else                                                        '// otherwise default to add
  559.       DefaultButton = 0
  560.    End If
  561.  
  562.    Count = 0
  563.    ForAll Obj In Selection.SelectedObjects               '// finds text shapes and stores text
  564.       If(Obj.isText) Then
  565.             Index = Count
  566.          If(Count <> 0)    Then
  567.                While((Index > 0) AND (SectionInfo(Index).TopPos < Obj.Top))    '// find a SectionInfo on same level
  568.                     SectionInfo(Index+1) = SectionInfo(Index)
  569.                     Index = Index - 1
  570.                 Wend
  571.                 If(SectionInfo(Index).LeftPos > Obj.Left) Then                        '// set to correct column
  572.                     SectionInfo(Index+1) = SectionInfo(Index)
  573.                     Index = Index - 1
  574.                 End If
  575.             End If
  576.             SectionInfo(Index+1).TopPos = Obj.Top
  577.             SectionInfo(Index+1).LeftPos = Obj.Left
  578.             SectionInfo(Index+1).Text = Obj.Text
  579.          Count = Count + 1
  580.  
  581.     For  x = 1 to Count
  582.     print SectionInfo(x).Text, SectionInfo(x).leftpos, SectionInfo(x).TopPos
  583.     next x
  584.     print "------------"
  585.  
  586.       End If
  587.    End ForAll
  588.  
  589.    Set Section = Selection.Group()
  590.  
  591.    If(Count > NumSections) Then                                        '//  if diagram has incorrect layout, too much text
  592.       MESSAGEBOX InvalidDiagram, 0, ErrorMsg
  593.    Else
  594.       DgmPath = [Freelance].Preferences.TemplateDir + SectionDgmFileName
  595.  
  596.         If(NumSections = MaxSegments) Then
  597.             MaxSpinnerVal = (MaxSegments/2) - 1
  598.         Else
  599.             MaxSpinnerVal = (NumSections/2)
  600.         End If
  601.  
  602.         MaxDeleteVal = (NumSections/2)-1 
  603.          PackedVal = CurrentDocument.RunDialog(1, SectionDlgTitle, DiagramNote, SectionAddQuestion, SectionDelQuestion, _
  604.                                                 DefaultButton, NULLSTR, NULLSTR, _
  605.                                                 "1", STR$(MaxSpinnerVal), 1, MaxDeleteVal)
  606. print numsections
  607.       If((PackedVal AND BitField9) = BitField9) Then               '// User ok'd dlg
  608.          If((PackedVal AND BitField8) <> BitField8) Then           '// ADD section
  609.             NumToAdd = PackedVal AND BitFields0To7
  610.             If((NumToAdd > 0) AND (NumToAdd <= 7)) Then
  611.                If(NumSections = MaxSegments) Then                   '// too many Section, can't add
  612.                   MESSAGEBOX AddError, 0, ErrorMsg
  613.                    Section.PutIntoPlacementBlock(DgmPBID)             '// restore dgm in pb
  614.                         Section.Name = SegmentDgmName                      '// so we can find it later
  615.                 Else                                                     '// add goal
  616.                   Section.Cut                                       '// remove old dgm
  617.                   Set Section = CurrentPage.CreateSymbol(DgmPath, (NumSections/2)+16)
  618.                         Selection.ClearSelection
  619.                   Section.Ungroup
  620.  
  621.                   FindSegmentTextShapes SectionInfo()               '// Find coordinates for each section and sort
  622.  
  623.                         x = NumSections + 2                                        '// clear one more for a whole level
  624.                         While(x > ((NumToAdd)*2)+1)
  625.                             SectionInfo(x).Text = SectionInfo(x-2).Text
  626.                             x = x - 1
  627.                         Wend
  628.  
  629.                   SectionInfo((NumToAdd*2)+1).Text = ""             '// not necessary since not used, but just to be safe
  630.                         SectionInfo((NumToAdd*2)+2).Text = ""
  631.  
  632.                   For x = 1 TO ((NumToAdd)*2)                          '// re-insert old Section
  633.                      Set Temp = SelectSegment(x, SectionInfo())
  634.                             If(StrCompare(SectionInfo(x).Text, NULLSTR)) Then    '// Don't replace text if No text, this will
  635.                          Temp.Text = SectionInfo(x).Text                        '// keep prompt text
  636.                             End If
  637.                   Next x
  638.                   For x = ((NumToAdd*2)+3) TO (NumSections+2)
  639.                      Set Temp = SelectSegment(x, SectionInfo())
  640.                             If(StrCompare(SectionInfo(x).Text, NULLSTR)) Then    '// Don't replace text if No text, this will
  641.                          Temp.Text = SectionInfo(x).Text                        '// keep prompt text
  642.                             End If
  643.                   Next x
  644.  
  645.                   set Section = Selection.Group()                   '// put pieces back together
  646.                   Section.PutIntoPlacementBlock(DgmPBID)              '// assume pb has id of 101
  647.                   Section.Name = SegmentDgmName                      '// so we can find it later
  648.                End If
  649.             End If
  650.          Else                                                        '// delete segment
  651.             NumToDel = PackedVal AND BitFields0To7
  652.             If(NumSections = MinSegments) Then
  653.                MESSAGEBOX DeleteError, 0, ErrorMsg
  654.                Section.PutIntoPlacementBlock(DgmPBID)                '// restore segment in pb
  655.                     Section.Name = SegmentDgmName                         '// so we can find it later
  656.             ElseIf ((NumToDel <= NumSections) AND (NumToDel > 0)) Then
  657.                Section.Cut
  658.                Set Section = CurrentPage.CreateSymbol(DgmPath, (NumSections/2)+14)
  659.                     Selection.ClearSelection
  660.                Section.Ungroup
  661.  
  662.                FindSegmentTextShapes SectionInfo()                     '// Find coordinates for each section and sort
  663.  
  664.                For x = ((NumToDel*2)+1) TO (NumSections-2)          '// delete segment in array of Sectiontruct's
  665.                   SectionInfo(x).Text = SectionInfo(x+2).Text
  666.                Next x
  667.                     
  668.                SectionInfo(NumSections-1).Text = ""
  669.                SectionInfo(NumSections).Text = ""                    '// clear last item in array
  670.  
  671.                For x = 1 TO (NumSections-2)                            '// re-insert old Section
  672.                   Set Temp = SelectSegment(x, SectionInfo())
  673.                         If(StrCompare(SectionInfo(x).Text, NULLSTR)) Then    '// Don't replace text if No text, this will
  674.                       Temp.Text = SectionInfo(x).Text                        '// keep prompt text
  675.                         End If
  676.                Next x
  677.  
  678.                Set Section = Selection.Group()                       '// put pieces back together
  679.                Section.PutIntoPlacementBlock(DgmPBID)
  680.                Section.Name = SegmentDgmName                      '// so we can find later
  681.             End If
  682.          End If
  683.       Else
  684.          Section.PutIntoPlacementBlock(DgmPBID)                        '// user canceled out of dlg
  685.             Section.Name = SegmentDgmName                                '// restore dgm in pb
  686.       End If                                             
  687.       Selection.ClearSelection
  688.    End If
  689. END SUB
  690.  
  691.  
  692. '//--------------------------------------------------------------------------------------
  693. '// Three column Segment script
  694. '//--------------------------------------------------------------------------------------
  695.  
  696. '// sets new coordinates for Level - does not store text
  697. PRIVATE SUB Find3ColSection(SectionInfo() As SegmentStruct)
  698.    Dim    Index    As Integer,    _
  699.            Count As Integer,    _
  700.            i        As Integer, _
  701.             x as integer
  702.  
  703.     For x = 1 To MaxSegments
  704.         SectionInfo(x).TopPos = 0
  705.         SectionInfo(x).LeftPos = 0
  706.     Next x
  707.  
  708.    Count = 0
  709.    ForAll Object in Selection.SelectedObjects
  710.       If(Object.IsText) Then
  711.             Index = Count
  712.          If(Count <> 0) Then
  713.                While((Index > 0) AND (SectionInfo(Index).TopPos < Object.Top))
  714.                         SectionInfo(Index+1).TopPos = SectionInfo(Index).TopPos
  715.                         SectionInfo(Index+1).LeftPos = SectionInfo(Index).LeftPos
  716.                         Index = Index - 1
  717.                 Wend
  718.                 If(SectionInfo(Index).LeftPos > Object.Left AND SectionInfo(Index).TopPos <= Object.Top) Then    
  719.                     SectionInfo(Index+1).TopPos = SectionInfo(Index).TopPos
  720.                     SectionInfo(Index+1).LeftPos = SectionInfo(Index).LeftPos
  721.                     Index = Index - 1
  722.                 End If
  723.                 If(SectionInfo(Index).LeftPos > Object.Left AND SectionInfo(Index).TopPos <= Object.Top) Then                        
  724.                     SectionInfo(Index+1).TopPos = SectionInfo(Index).TopPos
  725.                     SectionInfo(Index+1).LeftPos = SectionInfo(Index).LeftPos
  726.                     Index = Index - 1
  727.                 End If
  728.             End If
  729.             SectionInfo(Index+1).TopPos = Object.Top
  730.             SectionInfo(Index+1).LeftPos = Object.Left
  731.          Count = Count + 1
  732.  
  733.     For  x = 1 to Count
  734.     print SectionInfo(x).Text, SectionInfo(x).leftpos, SectionInfo(x).TopPos
  735.     next x
  736.     print "------------"
  737.  
  738.       End If
  739.    End ForAll
  740. END SUB
  741.  
  742.  
  743. PUBLIC SUB ThreeColumnSection()
  744.    Dim     PackedVal        As Long,        _
  745.            DgmPath            As String,    _
  746.            MaxSpinnerVal    As Integer,    _
  747.            MaxObjectCount    As Integer,    _
  748.            MinObjectCount As Integer, _
  749.            NumSections        As Integer, _
  750.            Count                As Integer,    _
  751.            DefaultButton    As Integer, _
  752.            x                    As Integer, _
  753.            NumToAdd            As Integer, _
  754.             NumToDel            As Integer, _
  755.             i                    As Integer, _
  756.             Index                As Integer,    _
  757.             MaxDeleteVal    As Integer, _
  758.            Section            As DrawObject,    _
  759.            Temp                As DrawObject,    _
  760.            SectionInfo(Max3ColSections)    As SegmentStruct
  761.    
  762.  
  763.    MaxObjectCount = Max3ColSections + 1
  764.    MinObjectCount    = Min3ColSections + 1
  765.  
  766.    For x = 1 to Max3ColSections                             '// Init array of SegmentStruct's
  767.         SectionInfo(x).LeftPos        = 0
  768.         SectionInfo(x).TopPos         = 0
  769.       SectionInfo(x).Text     = ""
  770.    Next x
  771.  
  772.    Set Temp = CurrentPage.FindObject(SegmentDgmName)  '// find Section diagram
  773.    Set Section = Temp.Replicate()                        '// take dgm out of pb to ungroup
  774.    Temp.Cut                                            '// delete dgm in pb
  775.     Selection.ClearSelection
  776.    Section.Ungroup                                       '// ungroup dgm copied - not in pb
  777.  
  778.    If(Selection.SelectionCount < MinObjectCount OR Selection.SelectionCount > MaxObjectCount) Then
  779.       MessageBox InvalidDiagram, 0, ErrorMsg
  780.       EndScript
  781.    End If                                                     '// Checking for invalid diagram
  782.  
  783.    SELECT CASE(Selection.SelectionCount)                  '// Find number of segments
  784.        Case 7: NumSections = 6
  785.        Case 10: NumSections = 9
  786.        Case 13: NumSections = 12
  787.        Case 16: NumSections = 15
  788.        Case 19: NumSections = 18
  789.    END SELECT
  790.  
  791.    If(NumSections = Max3ColSections) Then                  '// if max number of segments, default to delete
  792.       DefaultButton = 1
  793.    Else                                                        '// otherwise default to add
  794.       DefaultButton = 0
  795.    End If
  796.  
  797.    Count = 0
  798.    ForAll Obj In Selection.SelectedObjects               '// finds text shapes and stores text
  799.       If(Obj.isText) Then
  800.             Index = Count
  801.          If(Count <> 0)    Then
  802.                While((Index > 0) AND (SectionInfo(Index).TopPos < Obj.Top))    '// find a SectionInfo on same level
  803.                     SectionInfo(Index+1) = SectionInfo(Index)
  804.                     Index = Index - 1
  805.                 Wend                                                                                
  806.                 If(SectionInfo(Index).LeftPos > Obj.Left AND SectionInfo(Index).TopPos <= Obj.Top) Then    
  807.                     SectionInfo(Index+1) = SectionInfo(Index)                            '// set to correct column
  808.                     Index = Index - 1
  809.                 End If
  810.                 If(SectionInfo(Index).LeftPos > Obj.Left AND SectionInfo(Index).TopPos <= Obj.Top) Then                        
  811.                     SectionInfo(Index+1) = SectionInfo(Index)
  812.                     Index = Index - 1
  813.                 End If
  814.             End If
  815.             SectionInfo(Index+1).TopPos = Obj.Top
  816.             SectionInfo(Index+1).LeftPos = Obj.Left
  817.             SectionInfo(Index+1).Text = Obj.Text
  818.          Count = Count + 1
  819.  
  820.     For  x = 1 to Count
  821.     print SectionInfo(x).Text, SectionInfo(x).leftpos, SectionInfo(x).TopPos
  822.     next x
  823.     print "------------"
  824.  
  825.       End If
  826.    End ForAll
  827.  
  828.    Set Section = Selection.Group()
  829.  
  830.    If(Count > NumSections) Then                                        '//  if diagram has incorrect layout, too much text
  831.       MESSAGEBOX InvalidDiagram, 0, ErrorMsg
  832.    Else
  833.       DgmPath = [Freelance].Preferences.TemplateDir + SectionDgmFileName
  834.  
  835.         If(NumSections = Max3ColSections) Then
  836.             MaxSpinnerVal = (Max3ColSections/3) - 1
  837.         Else
  838.             MaxSpinnerVal = (NumSections/3)
  839.         End If
  840.  
  841. print "Section Count = ",numsections
  842. print "MaxSpinnerVal = ",maxspinnerval
  843.  
  844.         MaxDeleteVal = (NumSections/3) - 1
  845.          PackedVal = CurrentDocument.RunDialog(1, SectionDlgTitle, DiagramNote, SectionAddQuestion, SectionDelQuestion, _
  846.                                                 DefaultButton, NULLSTR, NULLSTR, _
  847.                                                 "1", STR$(MaxSpinnerVal), 1, MaxDeleteVal)
  848.  
  849.       If((PackedVal AND BitField9) = BitField9) Then               '// User ok'd dlg
  850.          If((PackedVal AND BitField8) <> BitField8) Then           '// ADD section
  851.             NumToAdd = PackedVal AND BitFields0To7
  852.             If((NumToAdd > 0) AND (NumToAdd <= 5)) Then
  853.                If(NumSections = Max3ColSections) Then             '// too many Section, can't add
  854.                   MESSAGEBOX AddError, 0, ErrorMsg
  855.                    Section.PutIntoPlacementBlock(DgmPBID)             '// restore dgm in pb
  856.                         Section.Name = SegmentDgmName                      '// so we can find it later
  857.                 Else                                                     '// add goal
  858.                   Section.Cut                                       '// remove old dgm
  859.                   Set Section = CurrentPage.CreateSymbol(DgmPath, (NumSections/3)+21)
  860.                         Selection.ClearSelection
  861.                   Section.Ungroup
  862.  
  863.                   Find3ColSection SectionInfo()                       '// Find coordinates for each section and sort
  864.  
  865.                         x = NumSections + 3                                        '// clear one more for a whole level
  866.                         While(x > ((NumToAdd)*3)+3)
  867.                             SectionInfo(x).Text = SectionInfo(x-3).Text
  868. print SectionInfo(x).text
  869.                             x = x - 1
  870.                         Wend
  871.  
  872.                   SectionInfo((NumToAdd*3)+1).Text = ""             '// not necessary since not used, but just to be safe
  873.                         SectionInfo((NumToAdd*3)+2).Text = ""
  874.                         SectionInfo((NumToAdd*3)+3).Text = ""
  875.  
  876.                   For x = 1 TO ((NumToAdd)*3)                          '// re-insert old Section
  877.                      Set Temp = SelectSegment(x, SectionInfo())
  878.                             If(StrCompare(SectionInfo(x).Text, NULLSTR)) Then    '// Don't replace text if no text, to keep 
  879.                          Temp.Text = SectionInfo(x).Text                        '// prompt text
  880.                             End If
  881.                   Next x
  882.                   For x = ((NumToAdd*3)+4) TO (NumSections+3)
  883.                      Set Temp = SelectSegment(x, SectionInfo())
  884.                             If(StrCompare(SectionInfo(x).Text, NULLSTR)) Then    '// Don't replace text if no text, to keep 
  885.                          Temp.Text = SectionInfo(x).Text                        '// prompt text
  886.                             End If
  887.                   Next x
  888.  
  889.                   set Section = Selection.Group()                   '// put pieces back together
  890.                   Section.PutIntoPlacementBlock(DgmPBID)              '// assume pb has id of 101
  891.                   Section.Name = SegmentDgmName                      '// so we can find it later
  892.                End If
  893.             End If
  894.          Else                                                        '// delete segment
  895.             NumToDel = PackedVal AND BitFields0To7
  896.             If(NumSections = Min3ColSections) Then
  897.                MESSAGEBOX DeleteError, 0, ErrorMsg
  898.                Section.PutIntoPlacementBlock(DgmPBID)                '// restore segment in pb
  899.                     Section.Name = SegmentDgmName                         '// so we can find it later
  900.             ElseIf ((NumToDel <= NumSections) AND (NumToDel > 0)) Then
  901.                Section.Cut
  902.                Set Section = CurrentPage.CreateSymbol(DgmPath, (NumSections/3)+19)
  903.                     Selection.ClearSelection
  904.                Section.Ungroup
  905.  
  906.                Find3ColSection SectionInfo()                             '// Find coordinates for each section and sort
  907.  
  908.                For x = ((NumToDel*3)+1) TO (NumSections-3)          '// delete segment in array of Sectiontruct's
  909.                   SectionInfo(x).Text = SectionInfo(x+3).Text
  910.                Next x
  911.  
  912.                SectionInfo(NumSections-1).Text = ""
  913.                SectionInfo(NumSections-1).Text = ""
  914.                SectionInfo(NumSections).Text = ""                    '// clear last item in array
  915.  
  916.                For x = 1 TO (NumSections-3)                            '// re-insert old Section
  917.                   Set Temp = SelectSegment(x, SectionInfo())
  918.                         If(StrCompare(SectionInfo(x).Text, NULLSTR)) Then    '// Don't replace text if no text, to keep 
  919.                       Temp.Text = SectionInfo(x).Text                        '// prompt text
  920.                         End If
  921.                Next x
  922.  
  923.                Set Section = Selection.Group()                       '// put pieces back together
  924.                Section.PutIntoPlacementBlock(DgmPBID)
  925.                Section.Name = SegmentDgmName                      '// so we can find later
  926.             End If
  927.          End If
  928.       Else
  929.          Section.PutIntoPlacementBlock(DgmPBID)                        '// user canceled out of dlg
  930.             Section.Name = SegmentDgmName                                '// restore dgm in pb
  931.       End If                                             
  932.       Selection.ClearSelection
  933.    End If
  934. END SUB
  935.